package com.tencent.qcloud.tuikit.tuicontact.presenter;


import android.os.Bundle;

import com.tencent.qcloud.tuicore.TUIConstants;
import com.tencent.qcloud.tuicore.TUICore;
import com.tencent.qcloud.tuicore.component.interfaces.IUIKitCallback;
import com.tencent.qcloud.tuicore.util.ToastUtil;
import com.tencent.qcloud.tuikit.tuicontact.bean.ContactItemBean;
import com.tencent.qcloud.tuikit.tuicontact.model.ContactProvider;
import com.tencent.qcloud.tuikit.tuicontact.util.ContactUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class SettingProfilePresenter {
    private static final String TAG = SettingProfilePresenter.class.getSimpleName();

    private final ContactProvider provider;

    public SettingProfilePresenter(){
        provider = new ContactProvider();
    }


    public void setConversationTop(String chatId, boolean isSetTop) {
        HashMap<String, Object> param = new HashMap<>();
        param.put(TUIConstants.TUIConversation.CHAT_ID, chatId);
        param.put(TUIConstants.TUIConversation.IS_SET_TOP, isSetTop);
        TUICore.callService(TUIConstants.TUIConversation.SERVICE_NAME, TUIConstants.TUIConversation.METHOD_SET_TOP_CONVERSATION, param);
    }

    public void getC2CReceiveMessageOpt(List<String> userIdList, IUIKitCallback<Boolean> callback) {
        provider.getC2CReceiveMessageOpt(userIdList, new IUIKitCallback<Boolean>() {
            @Override
            public void onSuccess(Boolean data) {
                ContactUtils.callbackOnSuccess(callback, data);
            }

            @Override
            public void onError(String module, int errCode, String errMsg) {
                ContactUtils.callbackOnError(callback, TAG, errCode, errMsg);
            }
        });
    }

    public void setC2CReceiveMessageOpt(List<String> userIdList, boolean isReceiveMessage) {
        provider.setC2CReceiveMessageOpt(userIdList, isReceiveMessage, new IUIKitCallback<Void>() {
            @Override
            public void onSuccess(Void data) {

            }

            @Override
            public void onError(String module, int errCode, String errMsg) {

            }
        });
    }

    public boolean isTopConversation(String chatId) {
        HashMap<String, Object> param = new HashMap<>();
        param.put(TUIConstants.TUIConversation.CHAT_ID, chatId);
        Object result = TUICore.callService(TUIConstants.TUIConversation.SERVICE_NAME,
                TUIConstants.TUIConversation.METHOD_IS_TOP_CONVERSATION, param);
        if (result instanceof Bundle) {
            return ((Bundle) result).getBoolean(TUIConstants.TUIConversation.IS_TOP, false);
        }
        return false;
    }

    public void isInBlackList(String id, IUIKitCallback<Boolean> callback) {
        provider.isInBlackList(id, new IUIKitCallback<Boolean>() {
            @Override
            public void onSuccess(Boolean data) {
                ContactUtils.callbackOnSuccess(callback, data);
            }

            @Override
            public void onError(String module, int errCode, String errMsg) {
                ToastUtil.toastShortMessage("getBlackList error , code = " + errCode + ", desc = " + errMsg);
                ContactUtils.callbackOnError(callback, errCode, errMsg);
            }
        });
    }

    public void getUsersInfo(String id, IUIKitCallback<List<ContactItemBean>> iuiKitCallback) {
        ArrayList<String> list = new ArrayList<>();
        list.add(id);
        provider.getUserInfo(list, iuiKitCallback);
    }
}
